﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using WpfCourse.Common;

namespace WpfCourse.Model
{
    public class LoginModel : NotifyBase
    {
        private string _userName;

        public string UserName
        {
            get { return _userName; }
            set { _userName = value; this.DoNotify(); }
        }

        private string _password;

        public string Password
        {
            get { return _password; }
            set { _password = value; this.DoNotify(); }
        }

        private string _validationCode;

        public string ValidationCode
        {
            get { return _validationCode; }
            set { _validationCode = value; this.DoNotify(); }
        }

        private string _errorMessage;

        public string ErrorMessage
        {
            get { return _errorMessage; }
            set { _errorMessage = value; this.DoNotify(); }
        }

        private bool _logining;

        public bool Logining
        {
            get { return _logining; }
            set { _logining = value; this.DoNotify(); }
        }


        public bool Login()
        {
            this.Logining = true;

            if (string.IsNullOrEmpty(this.UserName))
            {
                this.ErrorMessage = "请输入用户名！";
                this.Logining = false;
                return false;
            }

            if (string.IsNullOrEmpty(this.Password))
            {
                this.ErrorMessage = "请输入密码！";
                this.Logining = false;
                return false;
            }

            if (string.IsNullOrEmpty(this.ValidationCode))
            {
                this.ErrorMessage = "请输入验证码！";
                this.Logining = false;
                return false;
            }

            if (this.ValidationCode.ToLower() != "code")
            {
                this.ErrorMessage = "验证码不正确！";
                this.Logining = false;
                return false;
            }

            if (this.UserName != "admin" || this.Password != "jdsn")
            {
                this.ErrorMessage = "用户名或密码错误！";
                this.Logining = false;
                return false;
            }

            return true;
        }
    }
}
